import { Module, VuexModule, getModule, Mutation, MutationAction, Action } from 'vuex-module-decorators'
import store from '@/store'

export interface IUserState {
    cookie: string,
    roles: string[],
    avatar?: string
}

@Module({ dynamic: true, store, name: "user" })
class User extends VuexModule implements IUserState {
    public cookie: string = "aaaaaaaaaaaaaaaaaa"
    public roles: string[] = []
    public avatar: string = ""

    @Mutation
    public setCookie(param: string) {
        this.cookie = param
    }

    @Mutation
    public setRoles(params: string[]) {
        this.roles = params
    }

    @Mutation
    public setAvatar(param: string) {
        this.avatar = param
    }

    @MutationAction({ mutate: ["avatar", 'cookie', 'roles'] })
    async getUserInfo() {
        return {
            avatar: "asdfasdfsadfsadf",
            cookie: "asdfasdfasdfsad",
            roles: ["asdfasdfasdf", "asdfasdfasdf"]
        }
    }

}

export const UserModule = getModule(User)